<?php
	require_once dirname(__FILE__) . "/../../includes/config.php";
	require_once PHP_ROOTPATH.'/classes/database.php';
	//récupération des informations sur le test donné
	require ("../calcul_age.php");
	header("Content-Type: text/xml; charset=utf-8");
	echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
	echo "<list>";
	 
	$type_test = (isset($_POST["type_test"])) ? html_entity_decode($_POST["type_test"]) : NULL;
	$id_anim = (isset($_POST["id"])) ? html_entity_decode($_POST["id"]) : NULL;
	$date_n = (isset($_POST["date_n"])) ? html_entity_decode($_POST["date_n"]) : NULL;
	echo $date_n;
	if ($type_test && $id_anim) {
		$id_connect=Database::getInstance();
		$query_temp = "SELECT date_test,experimentateur,mesure,resultat_test_simple.description 
		FROM resultat_test_simple,resultat_test,test,type_test 
		WHERE unite_mesure LIKE '%".pg_escape_string($type_test) ."%' AND id_animal='".$id_anim."'
		AND resultat_test_simple.id_res=resultat_test.id_res
		AND resultat_test.id_test=test.id_test AND test.id_type_test=type_test.id_type_test";
		
		$res_query = pg_query($id_connect , $query_temp) or die(pg_last_error());
		
		while ($back = pg_fetch_assoc($res_query)) {
			echo "<item id=\"Date du test\" name=\"".$back["date_test"]."\" />";
			if($back["date_test"]){
				$age=calcul_age($date_n,$back["date_test"]);
				echo "<item id=\"Age (mois)\" name=\"".$age."\" />";
				echo "<item id=\"Age (cycle)\" name=\"".$age/8;
				echo"\" />";
			}
			echo "<item id=\"Expérimentateur\" name=\"".$back["experimentateur"]."\" />";
			echo "<item id=\"Mesure\" name=\"" . $back["mesure"] . "\" />";
			echo "<item id=\"Description\" name=\"".$back["description"]."\" />";
		}
	}
	echo "</list>";

?>
